package Services

import (
	"Ahq/Models"
	"crypto/rand"
	"fmt"
	"math/big"
	"time"
)

type FormulaConfig struct {
	Length      int
	SymbolTypes []byte
	Carry       bool
	Digit       int64
}

func getSymbolType(types []byte) byte {
	if len(types) == 0 {
		return Models.Addition
	}
	index, _ := rand.Int(rand.Reader, big.NewInt(int64(len(types))))
	return types[index.Int64()]

}

var count int

func GenerateFormula(c *FormulaConfig) Models.Formula {
	bT := time.Now()
	defer func() {
		eT := time.Since(bT)
		fmt.Println("GenerateFormula Run time: ", eT)
	}()
	result := make([]byte, 0)
	for i := 1; i <= c.Length; i++ {
		if i > 1 {
			result = append(result, getSymbolType(c.SymbolTypes))
		}
		result = append(result, randomNumber(c.Digit)...)
	}
	return Models.Formula{string(result)}
}

func randomNumber(digit int64) []byte {
	random_number, _ := rand.Int(rand.Reader, big.NewInt(digit*10))
	return []byte(random_number.String())
}
